#!/bin/sh -e
#
# zzz-firstboot
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

FIRSTBOOT_WORK_DIR=/etc/kpc/firstboot/guest

firstboot_file="$FIRSTBOOT_WORK_DIR/yandi-first-boot.sh"
firstboot_bak="${firstboot_file}_bak"
firstboot_done="${firstboot_file}_done"
firstboot_lock="${firstboot_file}_lock"

# First boot script
if [ -x $firstboot_file ]; then
  if [ -f $firstboot_done ]; then
    mv -f $firstboot_file $firstboot_bak
  else
    (flock -x $firstboot_lock -c "$firstboot_file")&
  fi
fi

exit 0
